<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Document</title>
</head>
<body>
    <h1>Scroll to see the animation</h1>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>
    <div class="box">
        <h2>Content</h2>
    </div>

    <script>
        const boxes = document.querySelectorAll('.box')

        window.addEventListener('scroll',checkBoxes)

        checkBoxes()

        function checkBoxes(){
            // console.log(window.innerHeight );
            const triggerBottom = window.innerHeight / 5 * 4

            boxes.forEach(box =>{
                //  方法返回元素的大小及其相对于视口的位置。
                const boxTop = box.getBoundingClientRect().top
                console.log(box.getBoundingClientRect().top);
                if(boxTop < triggerBottom){
                    box.classList.add('show')
                } else {
                    box.classList.remove('show')
                }
            })
        }
    </script>
</body>
</html>